/************************************************************************************************* PROGRAMMINFO ************************************************************************************************** Funktion: ESP32 BT CAR APP ************************************************************************************************** Version: 11.03.2023 A135 ************************************************************************************************** Board: ESP32vn IoT UNO V1.0.4 ************************************************************************************************** C++ Arduino IDE V1.8.13 ************************************************************************************************** Einstellungen: https://dl.espressif.com/dl/package_esp32_index.json http://dan.drown.org/stm32duino/package_STM32duino_index.json https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json ************************************************************************************************** **************************************************************************************************/ #include "BluetoothSerial.h" #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif BluetoothSerial SerialBT; //-------------------------------------------------------------- int motor1Pin1 = 27; // pin 2 an L293D int motor1Pin2 = 16; // pin 7 an L293D int enable1Pin = 12; // pin 1 an L293D int motor2Pin1 = 25; // pin 10 an L293D int motor2Pin2 = 26; // pin 15 an L293D int enable2Pin = 13; // pin 9 an L293D int state; void setup() { Serial.begin(9600); SerialBT.begin("ESP32CAR"); //Bluetooth Name Serial.println("ESP32CAR wurde gestartet!"); // Outputs: pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(enable1Pin, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); pinMode(enable2Pin, OUTPUT); // Enable1Pins digitalWrite(enable1Pin, HIGH); digitalWrite(enable2Pin, HIGH); } void loop() { //Wenn gesendet wird, Zustand lesen und speichern if(SerialBT.available() > 0){ state = SerialBT.read(); } // 'F' = vorwaerts if (state == 'F') { Serial.println("Vorwaerts"); digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); } // 'R' = rechts else if (state == 'R') { Serial.println("Rechts"); digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); delay(500); } // 'S' = Stopp else if (state == 'S') { Serial.println("STOPP"); digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); } // 'L' = links else if (state == 'L') { Serial.println("Links"); digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); delay(500); } // 'B' = zurueck else if (state == 'B') { Serial.println("Rueckwaerts"); digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); } //Für Debugging Serial.println(state); }